home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 19.zip
/
BS1 part 19
/
Enigme a Oxford BS1.adf
/
edueni.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-27
|
31KB
|
1,288 lines
#define FORWARD extern
#define noire 0
#define rouge 1
#define verte 2
#define jaune 3
#define bleue 4
#define rose 5
#define cyane 6
#define blanc 7
#define fh 11
#define fb 10
#define fd 9
#define fg 8
#define del 127
#define clr 16
#define esc 27
#define spc 32
#define eCLIC 0x01
#define eCLAV 0x02
#undef NULL
#define NULL ((void *)0)
#define MEMOIRE 64000L
#define ALLOUER(a,b) ((a *)AllocMem(sizeof(a),b))
#define CREER(v,t,m) (v=(struct t *)AllocMem(sizeof(struct t),m))
#define LIBERER(x,t) FreeMem((char *)x,sizeof(struct t))
#define NOISENUMBER 1
#define abs(x) (x>=0)?x:-x
#define ecrtab(y,x) (*(tableau+x)=y)
#define litab(x) ((int)*(tableau+x))
typedef struct Chaine
{int len;
char c[256]; } CHAINE;
FORWARD char upcase();
extern struct Library *OpenLibrary();
extern void CloseLibrary();
extern struct Window *OpenWindow();
extern void CloseWindow();
extern struct Screen *OpenScreen();
extern void CloseScreen();
extern void ShowTitle();
extern void SetPointer();
extern void ClearPointer();
extern long OpenWorkbench();
extern long CloseWorkbench();
extern void ActivateWindow();
extern void ModifyIDCMP();
extern struct Message *GetMsg();
extern void ReplyMsg();
extern void Delay();
extern void *AllocMem();
extern void FreeMem();
extern void *AllocRaster();
extern void FreeRaster();
extern void InitBitMap();
extern void SetRGB4();
extern void SetDrMd();
extern void SetAPen();
extern void SetBPen();
extern void Draw();
extern void Move();
extern long BltBlitMap();
extern short Examine();
extern struct FileLock *Lock();
extern void Unlock();
extern struct FileHandle *Open();
extern long Read();
extern void Close();
UBYTE pointeurkm[128]=
{ 0x7e, 0x60, /* ~ ` */ 0x31, 0x26, /* 1 & */ 0x32, 0x16, /* 2 e' */
0x33, 0x22, /* 3 " */ 0x34, 0x27, /* 4 ' */ 0x35, 0x28, /* 5 ( */
0x36, 0xa4, /* 6 par*/ 0x37, 0x17, /* 7 e` */ 0x38, 0x21, /* 8 ! */
0x39, 0x63, /* 9 c, */ 0x30, 0x18, /* 0 a` */ 0xa1, 0x29, /* no ) */
0x5f, 0x2d, /* _ - */ 0x7c, 0x5c, /* | \ */ 0x00, 0x00, /* */
0x30, 0x30, /* 0 0 */ 0x41, 0x61, /* A a */ 0x5a, 0x7a, /* Z z */
0x45, 0x65, /* E e */ 0x52, 0x72, /* R r */ 0x54, 0x74, /* T t */
0x59, 0x79, /* Y y */ 0x55, 0x75, /* U u */ 0x49, 0x69, /* I i */
0x4f, 0x6f, /* O o */ 0x50, 0x70, /* P p */ 0xac, 0x5e, /* .. ^ */
0x2a, 0x24, /* * $ */ 0x00, 0x00, /* */ 0x31, 0x31, /* 1 1 */
0x32, 0x32, /* 2 2 */ 0x33, 0x33, /* 3 3 */ 0x51, 0x71, /* Q q */
0x53, 0x73, /* S s */ 0x44, 0x64, /* D d */ 0x46, 0x66, /* F f */
0x47, 0x67, /* G g */ 0x48, 0x68, /* H h */ 0x4a, 0x6a, /* J j */
0x4b, 0x6b, /* K k */ 0x4c, 0x6c, /* L l */ 0x4d, 0x6d, /* M m */
0x25, 0x11, /* % u` */ 0x24, 0x24, /* livre */ 0x24, 0x24, /* livre*/
0x34, 0x34, /* 4 4 */ 0x35, 0x35, /* 5 5 */ 0x36, 0x36, /* 6 6 */
0x3e, 0x3c, /* > < */ 0x57, 0x77, /* W w */ 0x58, 0x78, /* X x */
0x43, 0x63, /* C c */ 0x56, 0x76, /* V v */ 0x42, 0x62, /* B b */
0x4e, 0x6e, /* N n */ 0x3f, 0x2c, /* ? , */ 0x2e, 0x3b, /* . ; */
0x2f, 0x3a, /* / : */ 0x2b, 0x3d, /* + = */ 0x00, 0x00, /* */
0x2e, 0x2e, /* . . */ 0x37, 0x37, /* 7 7 */ 0x38, 0x38, /* 8 8 */
0x39, 0x39 /* 9 9 */
};
#define HAUTECRAN 20
struct GfxBase *GfxBase=NULL;
struct IntuitionBase *IntuitionBase=NULL;
struct Library *DiskfontBase=NULL;
UBYTE *lettres;
struct NewScreen newScreen={ 0,HAUTECRAN,320,200,4,0,0,NULL,CUSTOMSCREEN,
NULL,NULL,NULL,NULL};
struct NewWindow newWindow={ 0,0,320,200,0,0,RAWKEY,
BORDERLESS|NOCAREREFRESH|RMBTRAP,NULL,NULL,
NULL,NULL,NULL,320,200,320,200,CUSTOMSCREEN};
struct Screen *screen = NULL;
struct Window *window = NULL;
struct Window *amigadoswin = NULL;
struct RastPort *rastPort = NULL;
struct ViewPort *viewPort = NULL;
struct BitMap *bitMap = NULL;
struct IntuiMessage *intuiMessage = NULL;
UWORD *sourisOff; /*[]={0,0,0,0,0,0};*/
int c = 0;
struct sFen { int x,y,l,h; struct BitMap *bit; };
struct sFen fen[10];
CHAINE vide;
int a,i,j,k,touche,code,note;
int mousex,mousey,amousex,amousey,deltax,deltay;
UWORD longueur;
UBYTE *tableau ;
int variable[256] ;
LONG tabadr[11];
int pttab;
char nomfich[25] ;
char filename[25];
LONG adr_retour=0L;
LONG adresse=0L;
LONG pointe,pointer,n,memoire,kar;
int hauteur,posx,posy, typecr,c_fond,c_forme,c_over;
CHAINE buflig,bufsais,reponse;
BOOL cadre, souli, c_deux, musicok,sortie;
int numfen,nbfen,ptrfen;
int max,compteur,curse;
char ch;
int clicx,clicy;
int evenmt;
int maxpageLivre;
int a_pageLivre[11] ;
int pageLivre;
int a_base, zone,px,py,lg,c1,memo;
LONG a_champ;
CHAINE phrase[21];
int soluti[10][10],repons[10][10];
BYTE tableaubing[8]={120,60,0,-60,-120,-60,0,60};
BYTE *tablebing;
BYTE *NameNoise;
void show_mouse()
{
ClearPointer(window);
}
void hide_mouse()
{
SetPointer(window,sourisOff,1,16,0,0);
}
/******************** afiimbr asm ****************************/
#asm
cseg
public _afiimbr
_afiimbr:
movem.l d0-d7/a0-a4,-(sp)
clr.l d0
clr.l d1
clr.l d2
clr.l d3
clr.l d4
clr.l d5
clr.l d6
clr.l d7
jmp debut
suite move.b (a0),d6
and.l #$000000f0,d6
lsl.w #8,d6 ;couleurs
lsl.l #1,d6
swap d6
lsl.w #7,d6
swap d6
lsl.l #1,d6
lsr.w #7,d6
lsr.b #7,d6
move.b (a0)+,d4
btst #3,d4
beq nblong
nbcourt and.b #$7,d4
addq.b #1,d4 ;nombre de points
rts
nblong and.b #$7,d4
lsl.w #8,d4
move.b (a0)+,d4
addq.w #1,d4 ;nombre de points
rts
debut move.l 72(sp),a0 ; a0 = adrimage
move.l 76(sp),a1 ; a1 = adrplan
move.l 4(a1),a2 ; a2 = plan1
move.l 8(a1),a3 ; a3 = plan2
move.l 12(a1),a4 ; a4 = plan3
move.l (a1),a1 ; a1 = plan0
move.l 68(sp),d1 ; d1 = h
subq.l #1,d1 ; d1 = h-1
move.l 64(sp),d2 ; d2 = l
subq.l #1,d2 ; d2 = l-1
move.l 60(sp),d3 ; d3 = y
mulu #40,d3 ; d3 = y*40
add.l 56(sp),d3 ; d3 = y*40+x
lignes move.l d3,-(sp) ; position (debut de ligne) dans le plan
move.l d2,d7 ; initialise d7 avec d2 = largeur
colonnes move.l #7,d0 ;compteur des bits de l'octet du plan
clr.l d5 ;octet a ecrire dans un plan
bitsuivant cmp.w #0,d4
bne plans
bsr suite
plans lsl.l #1,d5 ;
add.l d6,d5
subq.w #1,d4
dbra d0,bitsuivant
move.b d5,0(a1,d3.l)
lsr.w #8,d5
move.b d5,0(a2,d3.l)
swap d5
move.b d5,0(a3,d3.l)
lsr.w #8,d5
move.b d5,0(a4,d3.l)
addq.l #1,d3
dbra d7,colonnes
move.l (sp)+,d3
add.l #40,d3
dbra d1,lignes
movem.l (sp)+,d0-d7/a0-a4
rts
#endasm
#asm
;sons(table,periode,longueur)
cseg
public _sons
public _silence
_sons:
ctlw: equ $dff096
c0thi: equ $dff0a0
c0tlo: equ c0thi+2
c0tl: equ c0thi+4
c0per: equ c0thi+6
c0vol: equ c0thi+8
c1thi: equ $dff0b0
c1tlo: equ c1thi+2
c1tl: equ c1thi+4
c1per: equ c1thi+6
c1vol: equ c1thi+8
intreqw: equ $dff09c
intreqr: equ $dff01e
run:
;PILE
;sp adr retour
;sp+4 adr table
;sp+8 periode
;sp+12 longueur
move.l 4(sp),c0thi
move.w 14(sp),c0tl
move.w 10(sp),c0per
move #$40,c0vol
move.l 4(sp),c1thi
move.w 14(sp),c1tl
move.w 10(sp),c1per
move #$40,c1vol
move.w #$8203,ctlw
rts
_silence:
movem.l d0,-(sp)
clr.l d0
move.w #$0780,intreqw
waitstop:
move.w intreqr,d0
and.w #$0180,d0
beq.s waitstop
move.w #3,ctlw
movem.l (sp)+,d0
rts
#endasm
/*********************** caracteres *********************/
#asm
; routine d'affichage de caractere
; void afi040(ascii,x,y,fond,forme,lettres,base)
; int ascii ;
; int x,y,fond,forme;
; UBYTE *lettres ;
; PLANEPTR *base: &(bitMap->Planes[0])
; ETAT DE LA PILE APRES MOVEM.
; sp+0 a4
; sp+4 a3
; sp+8 a2
; sp+12 a1
; sp+16 a0
; sp+20 d7
; sp+24 d6
; sp+28 d5
; sp+32 d4
; sp+36 d3
; sp+40 d2
; sp+44 d1
; sp+48 d0
; sp+52 adr retour
; sp+56 ascii
; sp+60 x
; sp+64 y
; sp+68 fond
; sp+72 forme
; sp+76 lettres
; sp+80 base
cseg
public _afi040
_afi040:
movem.l d0-d7/a0-a4,-(sp)
clr.l d0
clr.l d1
clr.l d2
clr.l d3
clr.l d4
clr.l d5
clr.l d6
clr.l d7
move.l 76(sp),a1 ; a1 --> lettres
move.l 56(sp),d0 ; d0 = ascii w
lsl.l #3,d0 ;
adda.l d0,a1 ; a1 = lettre+8*ascii
move.l 64(sp),d0 ; d0 = y
muls #40,d0 ; d0 = 40*y
add.l 60(sp),d0 ; d0 = 40*y+x
move.l 68(sp),d1 ; d1 = fond
move.l 72(sp),d2 ; d2 = forme
move.l #15,d7
sub.l d1,d7
move.l d7,d1
move.l #15,d7
sub.l d2,d7
move.l d7,d2
move.w #7,d3 ; 8 lignes
bouc1 move.l 80(sp),a0 ; base PLANEPTR
adda.l #12,a0 ; a0 --> ptr plan3
move.l (a0),a2 ; a2 --> plan3
move.w #3,d4 ; 4 plans
bouc2 move.b 0(a1,d3.w),d5 ; d5=ligne de matrice caractere
clr.l d6 ; d6 = 0
btst d4,d2 ; test plan de couleur caract
bne label0 ; pas de couleur caract ds ce plan
move.b d5,d6 ; d6=ligne de matrice caractere
label0 btst d4,d1 ; test plan de couleur fond
beq label1 ; oui
clr.l d5 ; non, effacement matrice caractere
bra label2 ; vers affichage
label1 not.b d5 ; matrice inverse
label2 or.b d6,d5 ;
move.b d5,0(a2,d0.w)
suba.l #4,a0
move.l (a0),a2
dbra d4,bouc2
add.l #40,d0
dbra d3,bouc1
movem.l (sp)+,d0-d7/a0-a4
rts
#endasm
/********************************************/
void delay(compte)
int compte;
{
Delay((long)compte/100);
}
void bell()
{sons(NameNoise,(UWORD)301,longueur);Delay(50); silence();}
void joumus(a )
int a;
{
UWORD musica[64];
int i;
musica[0] =253; musica[1] =284; musica[2] =301; musica[3] =284;
musica[4] =239; musica[5] =0; musica[6] =0; musica[7] =0;
musica[8] =213; musica[9] =239; musica[10] =253; musica[11] =239;
musica[12] =190; musica[13] =0; musica[14] =0; musica[15] =0;
musica[16] =179; musica[17] =189; musica[18] =201; musica[19] =189;
musica[20] =127; musica[21] =142; musica[22] =151; musica[23] =142;
musica[24] =127; musica[25] =142; musica[26] =151; musica[27] =142;
musica[28] =119; musica[29] =0; musica[30] =0; musica[31] =0;
musica[32] =142; musica[33] =0; musica[34] =119; musica[35] =0;
musica[36] =127; musica[37] =0; musica[38] =142; musica[39] =0;
musica[40] =159; musica[41] =0; musica[42] =142; musica[43] =0;
musica[44] =127; musica[45] =0; musica[46] =142; musica[47] =0;
musica[48] =159; musica[49] =0; musica[50] =142; musica[51] =0;
musica[52] =127; musica[53] =0; musica[54] =142; musica[55] =0;
musica[56] =159; musica[57] =0; musica[58] =169; musica[59] =0;
musica[60] =190; musica[61] =0; musica[62] =0; musica[63] =0;
if (musicok)
{
for (i =a*8;i<=(a+1)*8-1;i++)
if (musica[i]==0 ) delay(100);
else { sons(NameNoise,musica[i],longueur);
Delay(1);
silence();
}
}
}
void musbon()
{
joumus( random(4) );
}
void musmoyen()
{
if(musicok) { sons(NameNoise,(UWORD)479,longueur);Delay(50); silence();}
}
void musmauvais()
{
if (musicok) { sons(NameNoise,(UWORD)954,longueur);Delay(50); silence();}
}
void musfin()
{
int i;
for (i =1;i<=7;i++) joumus(i);
}
void musiqu(number )
int number;
{
switch( number ) {
case 0 : musbon();break;
case 1 : musmauvais();break;
case 2 : musmoyen();break;
}
}
int random(echelle)
int echelle;
{
return(rand()%echelle);
}
void lecture()
{
BOOL relache;
int caract,qualif;
ModifyIDCMP(window,RAWKEY);
evenmt = 0;
do
{
relache=FALSE;
while((intuiMessage=(struct IntuiMessage *)GetMsg(window->UserPort))!=NULL)
ReplyMsg(intuiMessage);
while((intuiMessage=(struct IntuiMessage *)GetMsg(window->UserPort))==NULL);
switch(intuiMessage->Class)
{
/* case MOUSEBUTTONS :
if((intuiMessage->Code)==SELECTDOWN)
{ evenmt=eCLIC; clicx=(int)intuiMessage->MouseX;
clicy=(int)intuiMessage->MouseY;
}
break;*/
case RAWKEY :
evenmt=eCLAV;
qualif=(int)intuiMessage->Qualifier;
caract=(int)intuiMessage->Code;
switch (caract)
{
case 0x0E :
case 0x1C :
case 0x2B :
case 0x2C :
case 0x3B : evenmt=0; break;
case 0x40 : ch=spc; break;
case 0x41 : ch=del; break;
case 0x43 :
case 0x44 : ch=13; break; /* RETURN et ENTER */
case 0x45 : ch=esc; break;
case 0x46 : ch=clr; break;
case 0x4C : ch=fh; break;
case 0x4D : ch=fb; break;
case 0x4E : ch=fd; break;
case 0x4F : ch=fg; break;
default : if(caract<=0x003F)
{ if( (qualif&0x0004) >> 2 ^ (qualif&0x0003)>0 )
ch=pointeurkm[caract*2];
else
ch=pointeurkm[caract*2+1];
if(qualif&0x0008) ch=upcase(ch)-64;
/* if((ch>='a') && (ch<='z')) ch=ch-32;*/
}
else
if(caract>=0x0080) relache=TRUE;
else{ evenmt=0; ch=255;}
break;
}
break;
}
ReplyMsg(intuiMessage);
while((intuiMessage=(struct IntuiMessage *)GetMsg(window->UserPort))!=NULL)
ReplyMsg(intuiMessage);
}
while(relache);
ModifyIDCMP(window,0L);
}
void fencoul(x,y,l,h,couleur)
int x,y,l,h,couleur;
{
SetDrMd(rastPort,JAM1);
SetAPen(rastPort,(long)couleur) ;
SetOPen(rastPort,(long)couleur) ;
RectFill( rastPort,(long)(x*8),(long)y,(long)((x+l)*8-1),(long)(y+h-1) ) ;
}
char *nomFichier(nom,suf)
char *nom,*suf;
{
strcpy( filename,"df0:");
strcat(filename,nom);
strcat(filename,suf);
return(filename);
}
void trait(x1,y1,x2,y2,c)
int x1,y1,x2,y2,c;
{
SetAPen(rastPort,(long)c);
Move(rastPort,(long)x1,(long)y1);
Draw(rastPort,(long)x2,(long)y2);
}
void ouvrefen(X,Y,L,H)
int X,Y,L,H;
{
int i;
X*=8; L*=8;
if(numfen<10)
{
fen[numfen].x=X; fen[numfen].y=Y; fen[numfen].l=L; fen[numfen].h=H;
fen[numfen].bit=AllocMem((long)sizeof(struct BitMap),MEMF_CLEAR);
InitBitMap(fen[numfen].bit,4L,(long)L,(long)H);
if(fen[numfen].bit==NULL) fencoul(10,20,2,10,15);
for(i=0;i<4;i++)
if( (fen[numfen].bit->Planes[i]=(PLANEPTR)AllocRaster((long)L,(long)H) )==NULL)
fencoul(10,20,2,10,15);
if(( BltBitMap(bitMap,(long)X,(long)Y,fen[numfen].bit,0L,0L,(long)L,
(long)H, 0x00C0,0x00FF,NULL ))!=4L) fencoul(0,0,1,50,15);
numfen++;
}
}
void fermefen()
{
int i;
LONG X,Y,L,H;
if(numfen>0)
{
numfen--;
X=(long)fen[numfen].x; Y=(long)fen[numfen].y;
L=(long)fen[numfen].l;H=(long)fen[numfen].h;
BltBitMap(fen[numfen].bit,0L,0L,bitMap,X,Y,L,H,0x00C0,0x00FF,NULL);
for(i=0;i<4;i++) FreeRaster(fen[numfen].bit->Planes[i],L,H);
FreeMem(fen[numfen].bit,(long)sizeof(struct BitMap));
}
}
CHAINE fconcat(a,b,c)
char *a,*c;
CHAINE *b;
{
CHAINE x;
int i,j;
i=0;
for (;*a;a++) {i++; x.c[i]=*a; }
for(j=1;j<=b->len;j++) {i++; x.c[i]=b->c[j];}
for (;*c;c++) {i++; x.c[i]=*c; }
x.len=i; x.c[i+1]=0;
return(x);
}
#define concat(a,b,c) fconcat(a,&(b),c)
CHAINE cconcat(a,c)
CHAINE a;
char c;
{
a.len+=1;
a.c[a.len]=c;
a.c[a.len+1]=0;
return(a);
}
CHAINE fcopy(c,d,f)
CHAINE *c;
int d,f;
{
CHAINE x;
int i;
for(i=1;i<=f;i++) {x.c[i]=c->c[i+d-1];}
x.len=f; x.c[f+1]=0;
return(x);
}
#define copy(a,b,c) fcopy(&(a),b,c)
int fpos(s,c)
char *s;
CHAINE *c;
{
char *s1;
int i,j,t;
t=c->len-strlen(s)+1;
for(i=1;i<=t;i++)
{
for(j=i,s1=s;*s1 && j<=c->len && c->c[j]==*s1 ;s1++,j++) ;
if(!*s1) return(i);
}
return(0);
}
#define pos(a,b) fpos(a,&(b))
void fdelete(c,d,f)
CHAINE *c;
int d,f;
{
int i;
for(i=d+f;i<=c->len;i++) c->c[i-f]=c->c[i];
c->len-=f;
c->c[c->len+1]=0;
}
void finsert(s,c,p)
char *s;
CHAINE *c;
int p;
{
int i,j;
j=strlen(s);
for(i=c->len;i>=p;i--) c->c[i+j]=c->c[i];
for(i=p;*s;s++,i++) c->c[i]=*s;
c->len+=j;
c->c[c->len+1]=0;
}
void fcinsert(cc,c,p)
char cc;
CHAINE *c;
int p;
{
for(i=c->len;i>=p;i--) c->c[i+1]=c->c[i];
c->c[p]=cc;
c->len+=1;
c->c[c->len+1]=0;
}
#define delete(a,b,c) fdelete(&(a),b,c)
#define insert(a,b,c) finsert(a,&(b),c)
#define cinsert(a,b,c) fcinsert(a,&(b),c)
CHAINE atoch(s)
char *s;
{
CHAINE x;
int i;
i=0;
for(;*s;s++) {i++; x.c[i]=*s;}
x.len=i;
x.c[i+1]=0;
return(x);
}
CHAINE ctoch(c)
char c;
{
CHAINE x;
x.c[1]=c;
x.c[2]=0;
x.len=1;
return(x);
}
BOOL idem(a,b)
CHAINE a,b;
{
int i;
for(i=1;i<=a.len;i++) if (i>b.len||a.c[i]!=b.c[i]) return(FALSE);
if (a.len==b.len) return(TRUE); else return(FALSE);
}
#define length(x) (x.len)
char upcase(maj)
char maj;
{
if ((maj>96) && (maj<123)) return(maj-32);
else return(maj);
}
void effecr()
{ fencoul(0,0,40,200,4);}
void pass80()
{ typecr =80;effecr();}
void pass40()
{ typecr =40;effecr();}
void efffen( abscisse,ordonnee,larg,haut)
int abscisse, ordonnee, larg, haut;
{
if (typecr==80) fencoul(abscisse / 8,ordonnee,larg / 8,haut,4);
else fencoul(abscisse / 8,ordonnee,larg / 8,haut,4);
}
void prelig(max)
int max;
{
int lon;
BOOL sort;
buflig=atoch("");lon =0;sort =FALSE;
do
{
buflig =cconcat(buflig,(char)litab(pointe));
lon =lon+1;
switch( litab(pointe) ) {
case 123:
case 125:
case 91 :
case 93 : lon =lon-1;break;
case 0:
case 64 : delete (buflig,length(buflig),1);sort =TRUE; break;
}
pointe =pointe+1;
} while(!( (lon==max) || (sort)));
if (! sort )
{
int c;
c=litab(pointe);
while ( c==123||c==125||c==91||c==93)
{
buflig =cconcat(buflig,(char)c);pointe =pointe+1; c=litab(pointe);
}
switch( litab(pointe) ) {
case 32:
case 64:
case 0 : pointe =pointe+1;sort =TRUE;break;
}
if (pos(" ",buflig)==0 ) sort =TRUE;
if (! sort )
{
lon =length(buflig);
while ( buflig.c[lon]!=' '){ lon =lon-1;pointe =pointe-1;}
delete(buflig,lon,length(buflig)-lon+1);
}
}
}
void aficar(ascii)
char ascii;
{
int x1,x2,y1,y2,i,h;
x1=posx*8; x2=x1+7; h=hauteur/2-4;
for(i=0;i<h;i++)
{trait(x1,posy+7+i+1,x2,posy+7+i+1,c_fond);
trait(x1,posy-i-1,x2,posy-i-1,c_fond);}
afi040((int)ascii,posx,posy,c_fond,c_forme,lettres,&(bitMap->Planes[0]));
if(souli)
{
y1=posy+7+(hauteur-8)/2;
trait(x1,y1,x2,y1,c_forme);
}
if(cadre)
{
x1--; x2+=2; y1=posy+(hauteur-8)/2-1; y2=y1+9;
trait(x1,y1,x2,y1,c_forme); trait(x2,y1,x2,y2,c_forme);
trait(x2,y2,x1,y2,c_forme); trait(x1,y2,x1,y1,c_forme);
}
posx+=1; if(posx==typecr) { posx=0; posy+=hauteur;}
}
void afilig(tampon,x,y,c1,c2)
int x,y,c1,c2;
char *tampon;
{
char car;
int i;
c_forme=c1;
if(c_deux == TRUE) c_forme=c2;
posx=x; posy=y;
for(i=0;i<strlen(tampon);i++)
{
switch (tampon[i])
{
case '[': c_forme=c2; c_deux=TRUE; break;
case ']': c_forme=c1; c_deux=FALSE; break;
case '{': souli=TRUE; break;
case '}': souli=FALSE; break;
default : aficar(tampon[i]);
}
}
}
void curinv(xx,yy)
int xx,yy;
{
buflig =ctoch(bufsais.c[curse+1]);c_deux =TRUE;c_fond =7;
afilig(&(buflig.c[1]),xx,yy,0,0);
c_deux =FALSE;c_fond =4;
}
void fincurinv(xx,yy )
int xx,yy;
{ buflig =ctoch(bufsais.c[curse+1]);afilig(&(buflig.c[1]),xx,yy,blanc,blanc);}
void saisie (posx,posy,lon,debut)
int posx,posy,lon;
BOOL debut;
{
int lonpre,lgr ;
BOOL deuze ;
CHAINE aprelig ;
char l;
souli =FALSE;cadre =FALSE;deuze =TRUE;aprelig =atoch("");sortie =FALSE;
if (debut ) curse =0;
lgr =length(bufsais);
while ( length(bufsais)<80) bufsais =cconcat(bufsais,' ');
do {
if (lon+posx<typecr )
{
buflig =copy(bufsais,1,lon);
lonpre =lon;deuze =FALSE;
afilig(&(buflig.c[1]),posx,posy,blanc,blanc);
}
else
{
if ((lgr+posx<typecr) && (! deuze) )
{
buflig =copy(bufsais,1,typecr-posx);deuze =FALSE;
lonpre =lgr;afilig(&(buflig.c[1]),posx,posy,blanc,blanc);
}
else
{
buflig =copy(bufsais,1,typecr-posx);
while(buflig.c[length(buflig)]!=' '&&typecr+1-posx-length(buflig)<12)
delete(buflig,length(buflig),1);
if (buflig.c[length(buflig)]!=' ' ) buflig =copy(bufsais,1,typecr-posx);
lonpre =length(buflig);
if (lonpre>lgr )
{
lonpre =lgr;
if (deuze ) fencoul(0,posy+10,typecr,hauteur,c_fond);
deuze =FALSE;
}
else deuze =TRUE;
while ( length(buflig)<typecr-posx) buflig =cconcat(buflig,' ');
if (!idem(buflig,aprelig) )
{ aprelig =buflig;afilig(&(buflig.c[1]),posx,posy,blanc,blanc);}
if (deuze )
{
buflig =copy(bufsais,lonpre+1,typecr);
afilig(&(buflig.c[1]),0,posy+10,blanc,blanc);
}
}
}
do {
if ( (lonpre==lgr || curse<lonpre) && curse<typecr-posx )
curinv(posx+curse,posy);
else curinv(curse-lonpre,posy+10);
do lecture(); while(evenmt!=eCLAV);
if (((lonpre==lgr) || (curse<lonpre)) && (curse<typecr-posx) )
fincurinv(posx+curse,posy);
else fincurinv(curse-lonpre,posy+10);
switch( ch ) {
case fh : if (curse<=lonpre || (curse-lonpre)<posx ) bell();
else curse =curse-lonpre-posx;break;
case fb : if ((curse>lonpre) || (curse+lonpre+posx>lgr) ) bell();
else curse =curse+lonpre+posx;break;
case fd : curse =curse+1;if (curse>lgr )
{ curse =curse-1;bell();} break;
case fg : curse =curse-1;if (curse==-1)
{ curse =0;bell();} break;
}
} while( ch==fh||ch==fb||ch==fd||ch==fg);
switch( ch )
{
case del : if (curse>0 )
{
delete(bufsais,curse,1);bufsais =cconcat(bufsais,' ');
lgr =lgr-1;curse =curse-1;
}
else bell(); break;
case clr: if (lgr>curse )
{ delete(bufsais,curse+1,1);
bufsais =cconcat(bufsais,' ');
lgr =lgr-1;}
else bell();break;
case esc: sortie =TRUE;break;
default : if (((ch>31) && (ch<91)) || ((ch>96) && (ch<123)) )
{
if (lgr<lon )
{
bufsais =copy(bufsais,1,79);
curse =curse+1;cinsert(ch,bufsais,curse);
lgr =lgr+1;
}
else bell();break;
}
}
} while(!( (ch==13) || (ch==0) || (sortie==TRUE) ));
filtre();
}
void affiche(x,y,l,h,adresse)
int x,y,l,h;
LONG adresse;
{
afiimbr(x,y,l,h,adresse,&(bitMap->Planes[0]) );
}
void afiimage(pointer)
LONG pointer;
{
int large,haute,posix,posiy,taille,i;
int numero,numfich;
taille =litab(pointer+1)*256+litab(pointer+2);
large =litab(pointer+5);haute =litab(pointer+6);
posix =litab(pointer+3);posiy =litab(pointer+4);
if ((litab(pointer) & 63)==1 )
{
pointer =pointer+7;
affiche(posix,posiy,large,haute,tableau+pointer);
}
adr_retour =0;
}
int egal()
{
int i,diffec ;
sortie =FALSE;
if (idem(buflig,bufsais) ) { return(0);}
i=length(buflig)-length(bufsais);
if (i<-1 || i>1 ) return(2);
diffec =0;
if (length(buflig)==length(bufsais) )
{
for (i =1;i<=length(buflig);i++)
if (buflig.c[i]!=bufsais.c[i] ) diffec =diffec+1;
}
else
if (length(buflig)<length(bufsais) )
for (i =1;i<=length(buflig);i++)
if (buflig.c[i]!=bufsais.c[i] )
{
if (buflig.c[i]!=bufsais.c[i+1] ) return(2);
diffec =diffec+1;
if (diffec==1 ) delete(bufsais,i,1);
}
else
for (i =1;i<=length(bufsais);i++)
if (buflig.c[i]!=bufsais.c[i] )
{
if (bufsais.c[i]!=buflig.c[i+1] ) return(2);
diffec =diffec+1;
if (diffec==1 ) delete(buflig,i,1);
}
if (diffec==0 ) diffec =1;
if (diffec>2 ) diffec =2;
return(diffec);
}
void commen(number,endy )
int number,endy;
{
int nombre ;
int i;
pointe =litab(4L)*256+litab(5L);
if (pointe!=0 )
{
nombre =litab(pointe);pointe =pointe+1;
for (i =1;i<=number*nombre+random(nombre);i++)
pointe =pointe+litab(pointe)+1;
pointe =pointe+1;prelig(typecr);
afilig(&(buflig.c[1]),(typecr-length(buflig))/ 2,endy,jaune,jaune);
}
musiqu(number);
}
void initSons()
{
FILE *fp;
ULONG Length;
UWORD Smprate;
fp=fopen("df0:note.smp","r");
fread(&Length,sizeof(Length),1,fp);
fread(&Smprate,sizeof(Smprate),1,fp);
NameNoise=(BYTE *)AllocMem((long)Length,MEMF_CHIP|MEMF_CLEAR);
fread(NameNoise,Length,1,fp);
fclose(fp);
longueur=(UWORD)(Length/2);
}
void initCouleurs()
{
SetRGB4(&screen->ViewPort, 0L, 0L, 0L, 0L);
SetRGB4(&screen->ViewPort, 1L, 14L, 0L, 0L);
SetRGB4(&screen->ViewPort, 2L, 0L, 14L, 0L);
SetRGB4(&screen->ViewPort, 3L, 14L, 14L, 0L);
SetRGB4(&screen->ViewPort, 4L, 0L, 0L, 14L);
SetRGB4(&screen->ViewPort, 5L, 14L, 0L, 14L);
SetRGB4(&screen->ViewPort, 6L, 0L, 14L, 14L);
SetRGB4(&screen->ViewPort, 7L, 14L, 14L, 14L);
SetRGB4(&screen->ViewPort, 8L, 10L, 10L, 10L);
SetRGB4(&screen->ViewPort, 9L, 10L, 6L, 6L);
SetRGB4(&screen->ViewPort, 10L, 4L, 10L, 6L);
SetRGB4(&screen->ViewPort, 11L, 12L, 12L, 4L);
SetRGB4(&screen->ViewPort, 12L, 8L, 6L, 14L);
SetRGB4(&screen->ViewPort, 13L, 14L, 10L, 12L);
SetRGB4(&screen->ViewPort, 14L, 10L, 14L, 14L);
SetRGB4(&screen->ViewPort, 15L, 12L, 10L, 0L);
}
void initPolice()
{
FILE *fp;
fp = fopen("df0:lettres.bin","r");
lettres=(UBYTE *)AllocMem(sizeof(BYTE)*1024L,MEMF_PUBLIC|MEMF_CLEAR);
fread(lettres,1024L,1,fp);
fclose(fp);
}
void initMem()
{
tableau=(UBYTE *)AllocMem(MEMOIRE,MEMF_CHIP|MEMF_CLEAR);
}
LONG filesize(nom)
char *nom ;
{
struct FileLock *lock ;
LONG taille;
struct FileInfoBlock *fileInfoBlock;
fileInfoBlock = AllocMem((long)sizeof(struct FileInfoBlock),MEMF_CLEAR) ;
lock = Lock(nom,ACCESS_READ) ; if( lock == NULL ) return(-1) ;
if( Examine(lock,fileInfoBlock) == FALSE ) return(-1) ;
UnLock((long)lock) ;
taille=fileInfoBlock->fib_Size ;
FreeMem(fileInfoBlock,(long)sizeof(struct FileInfoBlock));
return(taille);
}
BOOL initMachine()
{
if( (GfxBase=(struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",0L))
== NULL ) return(FALSE);
if( (IntuitionBase=(struct IntuitionBase *)
OpenLibrary((UBYTE *)"intuition.library",0L))==NULL) return(FALSE);
amigadoswin = IntuitionBase->ActiveWindow;
sourisOff=AllocMem(6*sizeof(UWORD),MEMF_CHIP|MEMF_CLEAR);
if((screen=(struct Screen *)OpenScreen(&newScreen))==NULL) return(FALSE);
newWindow.Screen=screen;
if((window=(struct Window *)OpenWindow(&newWindow))==NULL) return(FALSE);
ShowTitle(screen,FALSE);
rastPort=&screen->RastPort;
bitMap=rastPort->BitMap;
viewPort=&screen->ViewPort;
srand((int)time(0L));
CloseWindow(amigadoswin);
CloseWorkBench();
hide_mouse();
ActivateWindow(window);
return(TRUE);
}
exitMachine()
{
if(window != NULL) CloseWindow(window);
if(screen != NULL) CloseScreen(screen);
OpenWorkBench();
if( IntuitionBase != NULL) CloseLibrary(IntuitionBase);
if( GfxBase != NULL) CloseLibrary(GfxBase);
exit();
}
void readfichier(nom,ptr)
char *nom;
UBYTE *ptr ;
{
struct FileHandle *file ;
LONG taille ;
taille = filesize(nom) ;
file = Open(nom,MODE_OLDFILE);
Read(file,ptr,taille) ;
Close(file) ;
}
void crefen(x,y,l,h)
int x,y,l,h ;
{
ouvrefen(x,y,l,h);
}
void restore()
{
fermefen();
}
void efface(couleur)
int couleur;
{
if(typecr == 40) fencoul(0,0,40,200,couleur);
}
void attente()
{
char car;
hauteur=8;
afilig("\010\011",typecr-2,192,rose,rose);
car=ch;
do lecture(); while(evenmt==0);
ch=car;
}
BOOL keypress()
{
return(TRUE);
}
LONG cconin()
{
lecture();
return((long)ch);
}
void exitJeu()
{
FreeMem(tableau,MEMOIRE);
}
void initCharge()
{
char car,cs[2];
c_fond=4;
car =choix();
cs[1]=(char)0;
if (! sortie)
{
cs[0]=car;
afilig(cs,35,160,blanc,blanc);
afilig("Voulez-vous des effets sonores (O/N) ?",1,184,rouge,rouge);
do { lecture();ch =upcase(ch);} while( ch!='O' && ch!='N');
musicok =(ch=='O');
afilig(" Chargement en cours... ",1,184,blanc,blanc);
strcpy(nomfich ,"episode "); nomfich[7]=car;
readfichier(nomFichier(nomfich,".tot"),tableau);
}
}
void initJeu()
{
numfen=0;
compteur=0;
vide.len=0;
vide.c[0]=0;
vide.c[1]=0;
initMem();
initCouleurs();
initPolice();
initSons();
}
main()
{
int i,j;
if(initMachine()==TRUE)
{
initJeu();
do
{
initCharge();
if (!sortie) executeur();
}
while (!sortie) ;
exitJeu() ;
}
exitMachine();
}